package cn.orangeframe.neon.application.mapper;

import cn.orangeframe.neon.application.exception.TerminateWorkflowException;
import cn.orangeframe.neon.domain.entity.WorkflowTask;
import cn.orangeframe.neon.domain.enums.TaskStatus;
import cn.orangeframe.neon.domain.model.TaskModel;
import cn.orangeframe.neon.domain.model.WorkflowModel;
import org.springframework.stereotype.Component;

import java.util.List;

import static cn.orangeframe.neon.domain.enums.TaskType.TASK_TYPE_TERMINATE;

@Component(TASK_TYPE_TERMINATE)
public class TerminateTaskMapper implements TaskMapper {

    @Override
    public String getTaskType() {
        return TASK_TYPE_TERMINATE;
    }

    @Override
    public List<TaskModel> getMappedTasks(TaskMapperContext taskMapperContext) throws TerminateWorkflowException {

        WorkflowModel workflowModel = taskMapperContext.getWorkflowInstance();
        WorkflowTask workflowTask = taskMapperContext.getTaskToSchedule();

        TaskModel task = taskMapperContext.createTaskModel();
        task.setTaskType(TASK_TYPE_TERMINATE);
        task.setStartTime(System.currentTimeMillis());
        task.setStatus(TaskStatus.IN_PROGRESS);
        return List.of(task);
    }
}
